﻿//-----------------------------------------------------------------------
// <copyright file="OSInfo.cs" company="Redmist">
//     Copyright (c) Damien T Smith. All rights reserved.
// </copyright>
// <author>Damien Smith</author>
//-----------------------------------------------------------------------

namespace Redmist.UsageMonitor.IconCreation
{
    using System;
    using System.Drawing;
    using Redmist.UsageMonitor.Properties;

    /// <summary>Contains methods for determing various information about the current operating system.</summary>
    public static class OSInfo
    {
        /// <summary>Attempts to determine the current width at which notify icons are currently being rendered by the operating system.</summary>
        /// <param name="graphics">A System.Drawing.Graphics representing a GDI+ drawing surface.</param>
        /// <returns>The preferred width for rendering notify icons.</returns>
        public static int RetrieveNotifyIconWidth(Graphics graphics)
        {
            if (Environment.OSVersion.Version.Major <= 5)
            {
                return Settings.Default.XpTrayIconOverride;
            }

            float dpi;
            using (graphics)
            {
                dpi = graphics.DpiX;
            }

            return (int)((dpi + 1) / 12) * 2;
        }
    }
}
